package vno.fux.map
{
	import flash.display.Sprite;
	import flash.events.Event;

	public class GridView extends BaseMapView
	{
		public function GridView(model_:MapModel, controller_:MapController)
		{
			super(model_, controller_);
			var canvas:Sprite = new Sprite;
			var numY:uint = _model.gridNumY;
			var numX:uint = _model.gridNumX;
			var cellSize:uint = _model.gridCellSize;
			canvas.graphics.beginFill(0x000000,1);
			var height:uint = numY*cellSize;
			var width:uint = numX*cellSize;
			canvas.graphics.lineStyle(2);
			for(var i:uint=0; i<numX; i++)
			{
				canvas.graphics.moveTo(i*cellSize,0);
				canvas.graphics.lineTo(i*cellSize,height);
			}
			for(var j:uint=0; j<numY; j++)
			{
				canvas.graphics.moveTo(0, j*cellSize);
				canvas.graphics.lineTo(width, j*cellSize);
			}
			var matrix:Vector.<Vector.<int>> = _model.gridMatrix;
			var halfCell:uint = cellSize/2;
			var r:uint = halfCell-2;
			canvas.graphics.lineStyle(0);
			canvas.graphics.beginFill(0xFF0000,1);
			for(var k:uint=0; k<matrix.length; k++)
			{
				var vector:Vector.<int> = matrix[k];
				for(var l:uint=0; l<vector.length; l++)
				{
					if(vector[l]>0)
					{
						//canvas.graphics.moveTo(k*cellSize+halfCell, l*cellSize+halfCell);
						canvas.graphics.drawCircle(k*cellSize+halfCell, l*cellSize+halfCell,r);
					}
				}
			}
			canvas.graphics.endFill();
			canvas.cacheAsBitmap = true;
			//this.cacheAsBitmap = true;
			this.content = canvas;
		}
		override public function update(evt:Event):void
		{
			this.setRegPoint([this._model.ox,this._model.oy]);
		}
	}
}